package com.sdgs.app.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * APP请求封装主类.
 * Created by chenzhen on 2018/01/16.
 */
public class AppRequest {

    /**
     * 平 台ID
     */
    private String partnerId;

    /**
     * 时间戳。
     */
    private String timestamp;

    /**
     * app版本。
     */
    private String sysVersion;

    /**
     * sign。
     */
    private String sign;

    /**
     * accessToken。
     */
    private String accessToken;

    /**
     * 业务数据json.
     */
    private String body;

    /**
     * jsonObj.
     */
    private JSONObject jsonObj;


    public AppRequest() {
    }

    public AppRequest(String partnerId, String timestamp, String sign, String sysVersion, String accessToken, String body) {
        this.partnerId = partnerId;
        this.timestamp = timestamp;
        this.sign = sign;
        this.sysVersion = sysVersion;
        this.accessToken = accessToken;
        this.setBody(body);
    }
    

    public String getPartnerId() {
        return partnerId;
    }

    public void setPartnerId(String partnerId) {
        this.partnerId = partnerId;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getSysVersion() {
        return sysVersion;
    }

    public void setSysVersion(String sysVersion) {
        this.sysVersion = sysVersion;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
        this.setJsonObj(JSON.parseObject(body));
    }

    public JSONObject getJsonObj() {
        return jsonObj;
    }

    public void setJsonObj(JSONObject jsonObj) {
        this.jsonObj = jsonObj;
    }
    
    public String getParamString(String key) {
        return jsonObj.getString(key);
    }
    
    
    public <T> T getParamObject(String key, Class<T> clazz) {
        return jsonObj.getObject(key, clazz);
    }
    
}
